﻿using System;
using System.Windows;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core;
using Baosight.ZNH.ZMCommon.ChildWindows;
using Baosight.Platform.Core.UI.Controls;

namespace Baosight.ZNH.ZMCM.UI.ChildWindows
{
    public partial class LevelBaseAccountStroeOut : EFViewCmes
    {
        public LevelBaseAccountStroeOut(String dialogType)
        {
            InitializeComponent();
            base.BeforeAction += this.OnBeforeAction;
            this.fdDate.Value = System.DateTime.Now.Date;
            base.Mode = OperationMode.Insert;
        }

        /// <summary>
        /// 初始化父类EFViewCmesProperty的值，每次点击“确定”、“返回”时执行此方法，重新赋值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.DataFields = this.InsertPanel.GetChildObjects<EFDataField>(null, true);
            base.ViewProperty = _view;
        }

        /// <summary>
        /// 确定按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommitClick(object sender, RoutedEventArgs e)
        {
            if (this.ValidateField())
            {
                base.OnCommitButtonClick("ZMCMG1", sender, e);
            }
        }

        /// <summary>
        /// 取消按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CancelClick(object sender, RoutedEventArgs e)
        {
            CmesWindows _window = this.Parent as CmesWindows;
            _window.DialogResult = false;
            _window.Close();
        }
        private void fdDepartment_ValueChanged(object sender, ValueChangedEventArgs e)
        {
            EFDataField field = sender as EFDataField;
            EFCustomDataPicker picker = field.Content as EFCustomDataPicker;
            if (picker.ItemObject != null)
            {
                if (!picker.ItemObject.Equals(""))
                {
                    this.fdDepartment.Value = picker.ItemObject.GetType().GetProperty("orgName").GetValue(picker.ItemObject, null);
                }
                else
                {
                    this.fdDepartment.Value = "";
                }
            }
        }

        #region customview 值获取
        /// <summary>
        /// Customview 取值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fdMaterialCode_ValueChanged(object sender, ValueChangedEventArgs e)
        {
            EFDataField field = sender as EFDataField;
            EFCustomDataPicker picker = field.Content as EFCustomDataPicker;
            if (picker.ItemObject != null)
            {
                if (!picker.ItemObject.Equals(""))
                {
                    this.fdMaterialName.Value = picker.ItemObject.GetType().GetProperty("fdMaterialName").GetValue(picker.ItemObject, null);
                    this.fdMaterialCode.Value = picker.ItemObject.GetType().GetProperty("fdMaterialCode").GetValue(picker.ItemObject, null);
                    this.fdQuality.Value = picker.ItemObject.GetType().GetProperty("fdQuality").GetValue(picker.ItemObject, null);
                    this.fdSpecModel.Value = picker.ItemObject.GetType().GetProperty("fdSpecModel").GetValue(picker.ItemObject, null);
                    this.fdNumber.Value = picker.ItemObject.GetType().GetProperty("fdNumber").GetValue(picker.ItemObject, null);
                    this.fdMaterialInnerCode.Value = picker.ItemObject.GetType().GetProperty("fdMaterialInnerCode").GetValue(picker.ItemObject, null);
                    this.fdPrice.Value = picker.ItemObject.GetType().GetProperty("fdPrice").GetValue(picker.ItemObject, null);
                    this.fdMetric.Value = picker.ItemObject.GetType().GetProperty("fdMetric").GetValue(picker.ItemObject, null);
                    this.fdMaterialType.Value = picker.ItemObject.GetType().GetProperty("fdMaterialType").GetValue(picker.ItemObject, null);
                    this.fdPlanPrice.Value = picker.ItemObject.GetType().GetProperty("fdPlanPrice").GetValue(picker.ItemObject, null);
                    this.fdMaterialId.Value = picker.ItemObject.GetType().GetProperty("fdMaterialId").GetValue(picker.ItemObject, null);

                }
                else
                {
                    this.fdMaterialId.Value = "";
                    this.fdMaterialName.Value = "";
                    this.fdMaterialCode.Value = "";
                    this.fdQuality.Value = "";
                    this.fdSpecModel.Value = "";
                    this.fdNumber.Value = "";
                    this.fdMaterialInnerCode.Value = "";
                    this.fdPrice.Value = "";
                    this.fdMetric.Value = "";
                    this.fdMaterialType.Value = "";
                    this.fdPlanPrice.Value = "";
                }
            }

        }
        #endregion
    }
}
